package stsj.meddroid.elements;

import stsj.meddroid.screen.BattleScreen;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle;

public class Vaccine {
	
	public final static int FREED  = 0;
	public final static int CAUGHT = 1;
	
	public int state;
	public int x;
	public int y;
	public Rectangle vaccineRectangle;
	public Sprite vaccineSprite;
	public int countFree = 400;
	public int countPlagued;
	
	public Vaccine (int a, int b){
		x = a;
		y = b;
		state = CAUGHT;
		vaccineSprite = new Sprite(BattleScreen.texImmunity,60,0,30,40);
		vaccineSprite.setPosition(x,y);
		vaccineRectangle = new Rectangle(x,y,30,40);
		countPlagued = 0;
	}

	public void moveDown(int i){
		y = y - i; 
		vaccineSprite.setPosition(x, y);
		if(state!=FREED){
			vaccineRectangle.setX(x);
			vaccineRectangle.setY(y);
		}
	}
	
	public void moveUp(int i){
		y = y + i;
		vaccineSprite.setPosition(x, y);
		if(state!=FREED){
			vaccineRectangle.setX(x);
			vaccineRectangle.setY(y);
		}
	}
	
	public void moveLeft(int i){
		x = x - i;
		vaccineSprite.setPosition(x, y);
		if(state!=FREED){
			vaccineRectangle.setX(x);
			vaccineRectangle.setY(y);
		}
	}
	
	public void moveRight(int i){
		x = x + i;
		vaccineSprite.setPosition(x, y);
		if(state!=FREED){
			vaccineRectangle.setX(x);
			vaccineRectangle.setY(y);
		}
	}
	
	public void setState(int x){state = x;}

	public int getState(){return state;}
	
	public void setX(int x) {
		this.x = x;
	}

	public void setY(int x) {
		this.y = x;
	}
//	
//	public int getX() {
//		return x;
//	}
//
//	public int getY() {
//		return y;
//	}
//
//	public Sprite getSprite() {
//		return vaccineSprite;
//	}
//	
//	public Rectangle getRectangle() {
//		return vaccineRectangle;
//	}
//
//	public int getCountFree() {
//		return countFree;
//	}
	
	public void free(){
		System.out.println("FREE");
		state = FREED;
		countFree = 240;
		BattleScreen.medDroid.healed(8);
		BattleScreen.medDroid.rechargeEnergy(8);
		vaccineRectangle.setX(0);
		vaccineRectangle.setY(0);
	}
	
	public void displayVaccine(){
		if (state==FREED){
			if ((countFree/40)%2==0){vaccineSprite.setRegion(30,0,30,40);}
			else{vaccineSprite.setRegion(0,0,30,40);}
			countFree--;
		}
		else{
			if(countPlagued == 80) {countPlagued = 0;}
			if ((countPlagued/40)%2==0){vaccineSprite.setRegion(60,0,30,40);}
			else{vaccineSprite.setRegion(90,0,30,40);}
			countPlagued++;
		}
	}
}
